#include <bits/stdc++.h>
using namespace std;
vector<int>node;
int main() {
	int n;
	char x = ' ';
	int y = 0;
	cin >> n;
	for(int i = 0; i < n; i++) {
		char a;
		cin >> a;
		if(a != x){
			if(i != 0) {
				//cout << y << ' ';
				node.push_back(y);
			}
			y = 0;
			x = a;
		}
		y++;
	}
	node.push_back(y);
	int maxn = 0;
	for(int i = 0; i < node.size(); i++) {
		//cout << node[i] << ' ';
		maxn = max(node[i] + node[(i + 1) % n], maxn);
	}
	cout << maxn;
	return 0;
}